#include "head.h"
#include <my_header.h>
int get_user_id(const char* name,user_group_t* group){
    if(strlen(name)>20){
        return -1;
    }
    char* pre_name=group->user_name[0];
    int name_count=0;
    while(strcmp(name,pre_name)!=0){
        name_count++;
        pre_name=group->user_name[name_count];
        if(name_count==group->count) return -1;
    }
    return name_count;
}
int create_user_id(const char*name,user_group_t* group){
    if(strlen(name)>20){
        return -1;
    }//名字太长
    if(group->count==12) return -1;//已经满员
    int new_id;
    for(int i=0;i<12;i++){
        if(group->free[i]==0){
            create_dir(name,i,group);
            create_stack(i,group);
            group->count++;
            strcpy(group->user_name[i],name);
            new_id=i;
            break;
        }
    }
    return new_id;
}
dir_t* create_dir(const char* name,int user_id,user_group_t* group){
    dir_t* new_dir=calloc(1,sizeof(dir_t));
    new_dir->name=name;
    group->dir_pointer[user_id]=new_dir;
    return new_dir;
}
char_stack_t* create_stack(int user_id,user_group_t* group){
    char_stack_t* new_stack=calloc(1,sizeof(char_stack_t));
    group->char_stack_pointer[user_id]=new_stack;
    return new_stack;
}
